Skip to content

Add aten._trilinear support to torch_lib core#2850

Open
WineChord wants to merge 7 commits into
microsoft:mainfrom
WineChord:add_trilinear_support
Open

Add aten._trilinear support to torch_lib core#2850
WineChord wants to merge 7 commits into
microsoft:mainfrom
WineChord:add_trilinear_support

Conversation

@WineChord

@WineChord WineChord commented Mar 12, 2026

Copy link
Copy Markdown

Summary

  • add an opset 18 torch_lib lowering for aten::_trilinear in core.py
  • add OpInfo coverage and keep expand*/sumdim arguments as Python tuples during ONNX tracing tests
  • validate _trilinear dimension lists before building the einsum equation

Testing

  • env -u LD_LIBRARY_PATH pytest tests/function_libs/torch_lib/ops_test.py -k "_trilinear" -vv
  • env -u LD_LIBRARY_PATH pytest tests/function_libs/torch_lib/ops_test.py -k "bilinear and not upsample" -vv

Context: requested from the review on pytorch/pytorch#177223.

@WineChord

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Comment thread onnxscript/function_libs/torch_lib/ops/core.py Outdated
@codecov

codecov Bot commented Mar 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.22222% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.65%. Comparing base (4c4f7a0) to head (da7166a).
⚠️ Report is 43 commits behind head on main.

Files with missing lines Patch % Lines
onnxscript/function_libs/torch_lib/ops/core.py 82.22% 5 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2850      +/-   ##
==========================================
+ Coverage   71.86%   72.65%   +0.78%     
==========================================
  Files         239      259      +20     
  Lines       29139    31709    +2570     
  Branches     2875     2989     +114     
==========================================
+ Hits        20942    23037    +2095     
- Misses       7219     7659     +440     
- Partials      978     1013      +35     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Comment thread tests/function_libs/torch_lib/ops_test_data.py Outdated

@justinchuby justinchuby left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Minor nits

@justinchuby justinchuby added the module: torchlib Related to the torch/aten function lib in development label Mar 12, 2026
Comment thread onnxscript/function_libs/torch_lib/ops/core.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a torch_lib lowering for aten::_trilinear (via ONNX Einsum) and wires it into the torch-lib OpInfo-based test harness to exercise the new lowering.

Changes:

  • Implement aten::_trilinear lowering in onnxscript/function_libs/torch_lib/ops/core.py by generating an einsum equation from expand*/sumdim.
  • Add OpInfo/sample-input coverage for torch.ops.aten._trilinear.default in tests/function_libs/torch_lib/extra_opinfo.py.
  • Register the new op test entry in tests/function_libs/torch_lib/ops_test_data.py.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/function_libs/torch_lib/ops_test_data.py Registers _trilinear in the torch_lib op test list.
tests/function_libs/torch_lib/extra_opinfo.py Adds OpInfo + sample inputs to drive _trilinear tests.
onnxscript/function_libs/torch_lib/ops/core.py Implements aten::_trilinear lowering using ONNX Einsum.

Comment thread onnxscript/function_libs/torch_lib/ops/core.py Outdated
Comment thread tests/function_libs/torch_lib/extra_opinfo.py
@justinchuby

Copy link
Copy Markdown
Collaborator

Can you consider the copilot comments as well?

Comment thread tests/function_libs/torch_lib/ops_test.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds TorchLib support for PyTorch’s internal aten::_trilinear op by lowering it to ONNX Einsum, and extends the TorchLib OpInfo test matrix to cover the new op.

Changes:

  • Add an opset18 TorchLib lowering for aten::_trilinear in onnxscript/function_libs/torch_lib/ops/core.py.
  • Add OpInfo/sample-input coverage for ops.aten._trilinear.default and register it in TorchLib test data.
  • Add dimension-list validation helpers for building the Einsum equation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/function_libs/torch_lib/ops_test_data.py Registers ops.aten._trilinear.default in TorchLib operator test data.
tests/function_libs/torch_lib/extra_opinfo.py Adds OpInfo + sample inputs for _trilinear to exercise tracing/export and numerical checks.
onnxscript/function_libs/torch_lib/ops/core.py Implements _trilinear lowering via op.Einsum and adds helpers to build/validate the equation.

Comment thread onnxscript/function_libs/torch_lib/ops/core.py Outdated
Comment on lines +114 to +118
class _FakeTensor:
__slots__ = ("shape",)

def __init__(self, shape: Sequence[int]):
self.shape = shape

@justinchuby justinchuby Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may use ir.value() to create these objects, instead of creating a fake tensor

@justinchuby justinchuby left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A nit comment

@justinchuby

Copy link
Copy Markdown
Collaborator

@WineChord could you check the previous comment before we can merge this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: torchlib Related to the torch/aten function lib in development

Projects

Development

Successfully merging this pull request may close these issues.

4 participants